package com.sxj.corejava.code16_单例模式;

/**
 * @author 石小俊
 */
public class Test03_ThreadLocal {

    public static void main(String[] args) {
        ThreadLocal<String> local = new ThreadLocal<>();
        // 赋值
        local.set("admin");
        // 取值
        System.out.println("当前线程:" + local.get());
        local.set("jack");
        System.out.println("当前线程:" + local.get());
        // 移除数据
        local.remove();

        new Thread() {
            @Override
            public void run() {
                local.set("张三");
                System.out.println("另一个线程:" + local.get());
            }
        }.start();

        System.out.println("当前线程:" + local.get());
    }

}
